﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.IO;

namespace DigitalAnts.App_Code.BAL.Utils
{
    public class clsUploadImage
    {
        public static bool uploadProductImage(FileUpload ful)
        {
            try
            {
                DirectoryInfo dInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/resource/product_pic"));
                if (!dInfo.Exists)
                {
                    dInfo.Create();
                }
                ful.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("~/resource/product_pic/" + ful.FileName));
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool uploadAvatarImage(FileUpload ful)
        {
            try
            {
                DirectoryInfo dInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/resource/user_avatar"));
                if (!dInfo.Exists)
                {
                    dInfo.Create();
                }
                ful.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("~/resource/user_avatar/" + ful.FileName));
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}